# Contributor: Francesco Colista <fcolista@alpinelinux.org>
# Maintainer: Francesco Colista <fcolista@alpinelinux.org>
pkgname=sslh
pkgver=1.22c
pkgrel=0
pkgdesc="Applicative Protocol Multiplexer (e.g. share SSH and HTTPS on the same port)"
url="http://www.rutschle.net/tech/sslh/README.html"
arch="all"
license="GPL-2.0-or-later"
makedepends="libconfig-dev libcap-dev pcre2-dev perl"
checkdepends="perl-conf-libconfig perl-io-socket-inet6 lcov valgrind"
subpackages="$pkgname-fail2ban::noarch $pkgname-doc $pkgname-openrc"
source="http://www.rutschle.net/tech/$pkgname/$pkgname-v$pkgver.tar.gz
	fix-make-install.patch
	fail2ban.patch
	config.patch
	$pkgname.initd
	$pkgname.confd
	"
builddir="$srcdir/$pkgname-v$pkgver"
# FIXME: Some tests fail.
# Can't test in chroot due to sockets and processes opened. (?)
options="!check"

build() {
	make CFLAGS="$CFLAGS -std=gnu99" \
		ENABLE_REGEX=1 \
		USELIBPCRE=1 \
		USELIBCONFIG=1 \
		USELIBCAP=1
}

check() {
	make test
}

package() {
	make DESTDIR="$pkgdir" PREFIX=/usr install

	install -D -m644 basic.cfg "$pkgdir/etc/$pkgname.conf"
	install -D -m755 "$srcdir/$pkgname.initd" "$pkgdir/etc/init.d/$pkgname"
	install -D -m644 "$srcdir/$pkgname.confd" "$pkgdir/etc/conf.d/$pkgname"
}

fail2ban() {
	install_if="$pkgname=$pkgver-r$pkgrel fail2ban"

	cd "$builddir"

	install -D -m644 scripts/fail2ban/sslh-ssh.conf \
		"$subpkgdir"/etc/fail2ban/filter.d/sslh-ssh.conf

	install -D -m644 scripts/fail2ban/jail.conf \
		"$subpkgdir"/etc/fail2ban/jail.d/sslh-ssh.conf
}

doc() {
	default_doc

	cd "$builddir"
	install -Dm 644 basic.cfg "$subpkgdir/usr/share/doc/$pkgname/basic.cfg"
	install -Dm 644 example.cfg "$subpkgdir/usr/share/doc/$pkgname/example.cfg"
}

sha512sums="
46c1221d7ba6db9d2c11ee9a05fd6ec1da758efe2ba5ac7df0ced7b884742b2cbcef6d88478cdd743055ed63c9db647687456ce4a9c95071fdd8d93c1b31ee4b  sslh-v1.22c.tar.gz
b82d3c799f0cdf183fe0545e1d2b4f142070112d7ec3594afd709608c4893c300122aa32026dd7f8e782eb3981bf85fc02f878e2613ddfe014f39bbb94fb441e  fix-make-install.patch
5773ee1d91e099726b614dbe385f2668699d25029fc300b664411c6082e95d3f27df11b9b1489bee3444c81bf941b8db13b4d382343788e47408c593c4531816  fail2ban.patch
cc6267d286e0f38b13cd4b2cba978627fbfad3781698ff7da7933c2d05356b34b60a62e766a32c0414cc26ce42bc043af11be35bd0af67692e587ca4d223357d  config.patch
20ad403c7e8bd37c849263886ff4307a478fbeaec74d52b7db864dea2e9bdafb2c501afd70fa2621385baf3536553a79cee006b4a629260921d2e08db7991696  sslh.initd
7eaf99c6fb4505d0562c46ed2b3ae656b7c7c96223f2c7f11ab1bed72e9df0223a7ef02277ac50a633d165238efb8c54044eff38b488a7884b6671120d9e3f3e  sslh.confd
"
